/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rie07;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author JBP
 */
@WebServlet(name = "Test1", urlPatterns = {"/Test1"}, initParams = {
    @WebInitParam(name = "compteur", value = "999")})
public class Test1 extends HttpServlet {
private int count=10;   

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/plain"); PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        Integer count = (Integer)session.getAttribute("count");
        Date madate = new Date();
        
        if(count==null)
            count = new Integer(1);
        else
            count = new Integer(count.intValue()+1);
        session.setAttribute("count", count);
        session.setAttribute("date", madate.toString());
        
        RequestDispatcher dispat = request.getRequestDispatcher("/Dispatcher");
        dispat.forward(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.print("Nom : " + request.getParameter("nom")+ " Prénom : " + request.getParameter("prenom"));
    }
        
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

